//
//  pickerCollectionViewCell.m
//  photoLibrayIos8
//
//  Created by jing zhao on 4/22/16.
//  Copyright © 2016 jing zhao. All rights reserved.
//

#import "PickerCollectionViewCell.h"

@interface PickerCollectionViewCell()

@property( assign, nonatomic )id<DelegatePickerCollectionViewCell> delegatePick;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation PickerCollectionViewCell

-(void)configureDataDictionary:(NSDictionary*)dic andDelegate:(id<DelegatePickerCollectionViewCell>)delete andIndexPath:(NSIndexPath*)indexPath{
    
    self.indexPath = indexPath;
    self.delegatePick = delete;
    self.dicData = dic;
    PHAsset *asset = [dic objectForKey:KEYAsset];
    BOOL boolSelect = [[dic objectForKey:KEYSelect]boolValue];
    
    self.buttonSelect.selected = boolSelect;
    self.viewOpacity.hidden = !boolSelect;
    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
    options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;

    [[PHImageManager defaultManager]requestImageForAsset:asset
                                              targetSize:self.buttonImage.frame.size
                                             contentMode:PHImageContentModeAspectFill
                                                 options:options
                                           resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
                                               [self.imageView setImage:result];
    }];
}

- (IBAction)tapselect:(id)sender {
    [self.delegatePick delegateAllSelectPickerCollectionViewCell:self];
}

- (IBAction)tapSelectCheck:(id)sender {
    [self.delegatePick delegateSelectPickerCollectionViewCell:self];
}


@end
